package org.soulraven.games.memory.ui.game.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.apache.log4j.Logger;
import org.soulraven.games.memory.ui.game.DisplayableCard;

public class FirstSelectionResolver implements ActionListener {

	private static final Logger LOGGER = Logger.getLogger(FirstSelectionResolver.class);

	private SelectionController controller = null;

	FirstSelectionResolver(final SelectionController controller) {
		this.controller = controller;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		LOGGER.debug("First selection");
		DisplayableCard card = (DisplayableCard) e.getSource();
		if (card.isSelectable()) {
			LOGGER.debug("Setting card number " + card.getNumber() + " as not selectable and visible");
			card.setSelectable(Boolean.FALSE);
			card.setHidden(Boolean.FALSE);
			controller.setPreviousSelection(card);
			controller.selectionFinished();
		}
	}
}
